//
// Created by wlk12 on 2024/3/1.
//
#include <iostream>
#include <memory>

class Job;

class Worker
{
public:
    Worker() = default;
    virtual ~Worker() = default;
    virtual void work(Job& job) = 0;
};

class WorkerA : public Worker
{
public:

    void work(Job& job) override
    {
        std::cout << "Work A" << std::endl;
    }
};

class WorkerB : public Worker
{
public:

    void work(Job& job) override
    {
        std::cout << "Work B" << std::endl;
    }
};

class WorkerC : public Worker
{
public:

    void work(Job& job) override
    {
        std::cout << "Work C" << std::endl;
    }
};

class Job
{
public:
    Job() = default;
    explicit Job(const std::shared_ptr<Worker>& work) : worker(work) {}
    void setWorker(const std::shared_ptr<Worker>& w)
    {
        this->worker = w;
    }

    void doJob()
    {
        if (this->worker != nullptr)
        {
            this->worker->work(*this);
        }
    }

private:
    std::shared_ptr<Worker> worker{};
};



int main()
{
    Job job;
    job.doJob();

    job.setWorker(std::make_shared<WorkerA>());
    job.doJob();

    job.setWorker(std::make_shared<WorkerB>());
    job.doJob();

    job.setWorker(std::make_shared<WorkerC>());
    job.doJob();

    return 0;
}